#include "t_blockinfo.h"
#include "t_setparams.h"
#include "ElaScrollPageArea.h"
#include "ElaText.h"
#include "ElaLineEdit.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGlobalStatic>

Q_GLOBAL_STATIC(T_BlockInfo,s_instance)

T_BlockInfo::T_BlockInfo(QWidget *parent)
    : ElaScrollPage(parent)
{
    initBlockInfo();
    initUI();

    connect(T_SetParamsIns,&T_SetParams::flushBlockInfo,this,&T_BlockInfo::on_flushBlockInfo);
}

T_BlockInfo::~T_BlockInfo()
{

}

T_BlockInfo *T_BlockInfo::Instance()
{
    return s_instance;
}

void T_BlockInfo::FlushInfo()
{
    on_flushBlockInfo();
}

void T_BlockInfo::initUI()
{
    // setMinimumWidth(780);
    // setMinimumHeight(300);
    setFixedSize(750,300);
    QWidget* centralWidget = new QWidget(this);
    centralWidget->setWindowTitle("电芯参数");

    QVBoxLayout* centerLayout = new QVBoxLayout(centralWidget);    
    centerLayout->setContentsMargins(0, 0, 0, 0);
    centerLayout->addWidget(m_blockInfoArea);
    centerLayout->addStretch();
    addCentralWidget(centralWidget, true, true, 0);

    // setPageTitleSpacing(0);
    // setTitleVisible(false);
}

void T_BlockInfo::initBlockInfo()
{
    ElaText *blockInfo_jgtype_text = new ElaText("结构类型：",this);
    blockInfo_jgtype_text->setWordWrap(false);
    blockInfo_jgtype_text->setTextPixelSize(12);
    m_blockInfo_jgtype_le = new ElaLineEdit(this);
    m_blockInfo_jgtype_le->setEnabled(false);

    ElaText *blockInfo_txtype_text = new ElaText("体系类型：",this);
    blockInfo_txtype_text->setWordWrap(false);
    blockInfo_txtype_text->setTextPixelSize(12);
    m_blockInfo_txtype_le = new ElaLineEdit(this);
    m_blockInfo_txtype_le->setEnabled(false);

    ElaText *blockInfo_inTemp_text = new ElaText("充电温度(℃)：",this);
    blockInfo_inTemp_text->setWordWrap(false);
    blockInfo_inTemp_text->setTextPixelSize(12);
    m_blockInfo_inTemp_le = new ElaLineEdit(this);
    m_blockInfo_inTemp_le->setEnabled(false);

    ElaText *blockInfo_outTemp_text = new ElaText("放电温度(℃)：",this);
    blockInfo_outTemp_text->setWordWrap(false);
    blockInfo_outTemp_text->setTextPixelSize(12);
    m_blockInfo_outTemp_le = new ElaLineEdit(this);
    m_blockInfo_outTemp_le->setEnabled(false);

    QHBoxLayout* hLayout_1 = new QHBoxLayout();
    hLayout_1->addWidget(blockInfo_jgtype_text);
    hLayout_1->addSpacing(5);
    hLayout_1->addWidget(m_blockInfo_jgtype_le);
    hLayout_1->addSpacing(10);
    hLayout_1->addWidget(blockInfo_txtype_text);
    hLayout_1->addSpacing(5);
    hLayout_1->addWidget(m_blockInfo_txtype_le);
    hLayout_1->addSpacing(10);
    hLayout_1->addWidget(blockInfo_inTemp_text);
    hLayout_1->addSpacing(5);
    hLayout_1->addWidget(m_blockInfo_inTemp_le);
    hLayout_1->addSpacing(10);
    hLayout_1->addWidget(blockInfo_outTemp_text);
    hLayout_1->addSpacing(5);
    hLayout_1->addWidget(m_blockInfo_outTemp_le);
    hLayout_1->addSpacing(10);

    ElaText *blockInfo_kWh_text = new ElaText("额定容量(Ah)：",this);
    blockInfo_kWh_text->setWordWrap(false);
    blockInfo_kWh_text->setTextPixelSize(12);
    m_blockInfo_kWh_le = new ElaLineEdit(this);
    m_blockInfo_kWh_le->setEnabled(false);

    ElaText *blockInfo_voltage_text = new ElaText("额定电压(V)：",this);
    blockInfo_voltage_text->setWordWrap(false);
    blockInfo_voltage_text->setTextPixelSize(12);
    m_blockInfo_voltage_le = new ElaLineEdit(this);
    m_blockInfo_voltage_le->setEnabled(false);

    ElaText *blockInfo_outStopVol_text = new ElaText("放电截至电压(V)：",this);
    blockInfo_outStopVol_text->setWordWrap(false);
    blockInfo_outStopVol_text->setTextPixelSize(12);
    m_blockInfo_outStopVol_le = new ElaLineEdit(this);
    m_blockInfo_outStopVol_le->setEnabled(false);

    ElaText *blockInfo_inStopVol_text = new ElaText("充电截至电压(V)：",this);
    blockInfo_inStopVol_text->setWordWrap(false);
    blockInfo_inStopVol_text->setTextPixelSize(12);
    m_blockInfo_inStopVol_le = new ElaLineEdit(this);
    m_blockInfo_inStopVol_le->setEnabled(false);

    QHBoxLayout* hLayout_2 = new QHBoxLayout();
    hLayout_2->addWidget(blockInfo_kWh_text);
    hLayout_2->addSpacing(5);
    hLayout_2->addWidget(m_blockInfo_kWh_le);
    hLayout_2->addSpacing(10);
    hLayout_2->addWidget(blockInfo_voltage_text);
    hLayout_2->addSpacing(5);
    hLayout_2->addWidget(m_blockInfo_voltage_le);
    hLayout_2->addSpacing(10);
    hLayout_2->addWidget(blockInfo_outStopVol_text);
    hLayout_2->addSpacing(5);
    hLayout_2->addWidget(m_blockInfo_outStopVol_le);
    hLayout_2->addSpacing(10);
    hLayout_2->addWidget(blockInfo_inStopVol_text);
    hLayout_2->addSpacing(5);
    hLayout_2->addWidget(m_blockInfo_inStopVol_le);
    hLayout_2->addSpacing(10);

    ElaText *blockInfo_outContinue_text = new ElaText("持续放电倍率：",this);
    blockInfo_outContinue_text->setWordWrap(false);
    blockInfo_outContinue_text->setTextPixelSize(12);
    m_blockInfo_outContinue_le = new ElaLineEdit(this);
    m_blockInfo_outContinue_le->setEnabled(false);

    ElaText *blockInfo_inContinue_text = new ElaText("持续充电倍率：",this);
    blockInfo_inContinue_text->setWordWrap(false);
    blockInfo_inContinue_text->setTextPixelSize(12);
    m_blockInfo_inContinue_le = new ElaLineEdit(this);
    m_blockInfo_inContinue_le->setEnabled(false);

    ElaText *blockInfo_out10_text = new ElaText("10秒峰值放电倍率：",this);
    blockInfo_out10_text->setWordWrap(false);
    blockInfo_out10_text->setTextPixelSize(12);
    m_blockInfo_out10_le = new ElaLineEdit(this);
    m_blockInfo_out10_le->setEnabled(false);

    ElaText *blockInfo_recircle_text = new ElaText("循环：",this);
    blockInfo_recircle_text->setWordWrap(false);
    blockInfo_recircle_text->setTextPixelSize(12);
    m_blockInfo_recircle_le = new ElaLineEdit(this);
    m_blockInfo_recircle_le->setEnabled(false);

    QHBoxLayout* hLayout_3 = new QHBoxLayout();
    hLayout_3->addWidget(blockInfo_outContinue_text);
    hLayout_3->addSpacing(5);
    hLayout_3->addWidget(m_blockInfo_outContinue_le);
    hLayout_3->addSpacing(10);
    hLayout_3->addWidget(blockInfo_inContinue_text);
    hLayout_3->addSpacing(5);
    hLayout_3->addWidget(m_blockInfo_inContinue_le);
    hLayout_3->addSpacing(10);
    hLayout_3->addWidget(blockInfo_out10_text);
    hLayout_3->addSpacing(5);
    hLayout_3->addWidget(m_blockInfo_out10_le);
    hLayout_3->addSpacing(10);
    hLayout_3->addWidget(blockInfo_recircle_text);
    hLayout_3->addSpacing(5);
    hLayout_3->addWidget(m_blockInfo_recircle_le);
    hLayout_3->addSpacing(10);

    ElaText *blockInfo_length_text = new ElaText("长度(mm)：",this);
    blockInfo_length_text->setWordWrap(false);
    blockInfo_length_text->setTextPixelSize(12);
    m_blockInfo_length_le = new ElaLineEdit(this);
    m_blockInfo_length_le->setEnabled(false);

    ElaText *blockInfo_width_text = new ElaText("宽度(mm)：",this);
    blockInfo_width_text->setWordWrap(false);
    blockInfo_width_text->setTextPixelSize(12);
    m_blockInfo_width_le = new ElaLineEdit(this);
    m_blockInfo_width_le->setEnabled(false);

    ElaText *blockInfo_height_text = new ElaText("厚度(mm)：",this);
    blockInfo_height_text->setWordWrap(false);
    blockInfo_height_text->setTextPixelSize(12);
    m_blockInfo_height_le = new ElaLineEdit(this);
    m_blockInfo_height_le->setEnabled(false);

    ElaText *blockInfo_weight_text = new ElaText("重量(g)：",this);
    blockInfo_weight_text->setWordWrap(false);
    blockInfo_weight_text->setTextPixelSize(12);
    m_blockInfo_weight_le = new ElaLineEdit(this);
    m_blockInfo_weight_le->setEnabled(false);

    QHBoxLayout* hLayout_4 = new QHBoxLayout();
    hLayout_4->addWidget(blockInfo_length_text);
    hLayout_4->addSpacing(5);
    hLayout_4->addWidget(m_blockInfo_length_le);
    hLayout_4->addSpacing(10);
    hLayout_4->addWidget(blockInfo_width_text);
    hLayout_4->addSpacing(5);
    hLayout_4->addWidget(m_blockInfo_width_le);
    hLayout_4->addSpacing(10);
    hLayout_4->addWidget(blockInfo_height_text);
    hLayout_4->addSpacing(5);
    hLayout_4->addWidget(m_blockInfo_height_le);
    hLayout_4->addSpacing(10);
    hLayout_4->addWidget(blockInfo_weight_text);
    hLayout_4->addSpacing(5);
    hLayout_4->addWidget(m_blockInfo_weight_le);
    hLayout_4->addSpacing(10);

    m_blockInfoArea = new ElaScrollPageArea(this);
    m_blockInfoArea->setFixedSize(750,250);
    // m_blockInfoArea->setMinimumWidth(750);
    // m_blockInfoArea->setMinimumHeight(200);
    QVBoxLayout* vLayout = new QVBoxLayout(m_blockInfoArea);
    vLayout->addLayout(hLayout_1);
    vLayout->addSpacing(10);
    vLayout->addLayout(hLayout_2);
    vLayout->addSpacing(10);
    vLayout->addLayout(hLayout_3);
    vLayout->addSpacing(10);
    vLayout->addLayout(hLayout_4);
    vLayout->addStretch();
}

void T_BlockInfo::on_flushBlockInfo()
{
    m_blockInfo_jgtype_le->setText(g_blockInfo.jgtype);
    m_blockInfo_txtype_le->setText(g_blockInfo.txtype);
    m_blockInfo_inTemp_le->setText(g_blockInfo.inTemp);
    m_blockInfo_outTemp_le->setText(g_blockInfo.outTemp);
    m_blockInfo_kWh_le->setText(QString::number(g_blockInfo.kWh,'f',2));
    m_blockInfo_voltage_le->setText(QString::number(g_blockInfo.voltage,'f',2));
    m_blockInfo_outStopVol_le->setText(QString::number(g_blockInfo.outStopVol,'f',2));
    m_blockInfo_inStopVol_le->setText(QString::number(g_blockInfo.inStopVol,'f',2));
    m_blockInfo_outContinue_le->setText(g_blockInfo.outContinue);
    m_blockInfo_inContinue_le->setText(g_blockInfo.inContinue);
    m_blockInfo_out10_le->setText(g_blockInfo.out10);
    m_blockInfo_recircle_le->setText(QString::number(g_blockInfo.recircle));
    m_blockInfo_length_le->setText(QString::number(g_blockInfo.length,'f',2));
    m_blockInfo_width_le->setText(QString::number(g_blockInfo.width,'f',2));
    m_blockInfo_height_le->setText(QString::number(g_blockInfo.height,'f',2));
    m_blockInfo_weight_le->setText(QString::number(g_blockInfo.weight));
}
